﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBModel;
using System.Web;
using System.Net;
using System.IO;
namespace TestWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //BllService.SysMenuService sys = new BllService.SysMenuService();
            //var list = sys.GetMenuListByParentID("0");

            var serr = new BllService.UserService();
            serr.UserLogin(txtUser.Text, txtPassword.Text);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            var str = Utility.Md5Heleper.Md5Encrypt(txtConn.Text);

            MessageBox.Show(Utility.Md5Heleper.Md5Decrypt(str));
        }

        private void button3_Click(object sender, EventArgs e)
        {



            AISmartEventServer.HzauthEventServer ss = new AISmartEventServer.HzauthEventServer();
            //ss.GetPersonList();

            //// 令牌获取
            //AISmartEventServer.HzauthEventServer.getToken();
            //string imgfile = ss.GetMotorvehicleList("2020-10-09 18:39:46");
            //ss.GetGaojin("2020-10-09 18:39:46","2020-10-15 18:39:46");
            //string imgurl = ss.GetImgFile(imgfile);
            //ss.GetPersonList();
            //ss.GetNonMotorvehicleList();
            //ss.GetFaceList();

            return;
            List<Model1> list = new List<Model1>();
            list.Add(new Model1 { id = "1", name = "chen1", sex = "2020-12-11 18:09:09", });
            list.Add(new Model1 { id = "2", name = "chen2", sex = "nan", });
            list.Add(new Model1 { id = "3", name = "chen3", sex = "nan", });
            ResultModel rest = new ResultModel();
            rest.code = 1;
            rest.count = 100;
            rest.msg = "成功";
            rest.data = list;  //new Model1 { id = "3", name = "chen3", sex = "nan", };

            TestBll com = new TestBll();
            string str = com.SerializeObject(rest);

        }

        public class Model1
        {
            public string id
            {
                get;
                set;
            }
            public string name
            {
                get;
                set;
            }
            public string sex
            {
                get;
                set;
            }
        }


        public class TestBll : BllService.DbCommon
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            //var personModel = new AIEventManagePersonModel();
            //personModel.person = new PersonModel
            //{
            //    ID = 929,
            //    Name = "张亮",
            //    Sex = "男",
            //    Age = 19,
            //    Dept = "tas",
            //    IDC = "490921199090291909",
            //    Remark = "",
            //    PersonType = 1,
            //    Phone = "132231332121",
            //};
            //personModel.B64_FacePics = new List<string>(){
            //Convert.ToBase64String(System.IO.File.ReadAllBytes(@"D:\Project\ComprehensiveGovernanceWeb\TempFile\2020070711243057368.jpg"))
            };
            #region MyRegion

            //请求路径
            string url = "http://127.0.0.1:58008/SmartAPIService/person/addperson";

            //定义request并设置request的路径
            WebRequest request = WebRequest.Create(url);

            //定义请求的方式
            request.Method = "POST";

            var postData = new { ip = "192.168.1.103", port = 8895, Person = new TestBll().SerializeObject(personModel) };

            var JsonData = new TestBll().SerializeObject(postData);
            //初始化request参数

            //设置参数的编码格式，解决中文乱码
            byte[] byteArray = Encoding.UTF8.GetBytes(JsonData);

            //设置request的MIME类型及内容长度
            request.ContentType = "application/json";

            request.ContentLength = byteArray.Length;

            //打开request字符流
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            //定义response为前面的request响应
            WebResponse response = request.GetResponse();

            //获取相应的状态代码
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);

            //定义response字符流
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();//读取所有
            Console.WriteLine(responseFromServer);

            //关闭资源
            reader.Close();
            dataStream.Close();
            response.Close();
            #endregion


            //AISmartEventServer.AIEventManagerServer server = new AISmartEventServer.AIEventManagerServer();
            //var person = new TestBll().SerializeObject(personModel);
            //server.AddPerson("192.168.1.103", 8895, person);
        }
    }
}
